﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using compshop.Infrastructure.CompShopDataService;
using compshop.Infrastructure;
using compshop.Modules.ListOfTransportationBills.View;
namespace compshop.Modules.ListOfTransportationBills.Presenter
{
  public  class TransportationBillsListPresenter
    {
        private CompShopEntities compShopDataContext;
        public IViewTransportationBillsList View { set; get; }
        private EventsManager eventsManager;
        public TransportationBillsListPresenter(EventsManager eventManager)
        {

            compShopDataContext = CompShopEntitiesContext.GetInstance();
            BillForTransportationList = compShopDataContext.BillForTransportations.ToList();
           
            eventsManager = eventManager;
            eventsManager.Presenter = this;
            eventsManager.Subscribe();
        }

        public void AscSort()
        {
            BillForTransportationList = BillForTransportationList.OrderBy(x => x.StartDate).ToList();
        }
        public void DescSort()
        {
            BillForTransportationList = BillForTransportationList.OrderByDescending(x => x.StartDate).ToList();
        }
        public List<BillForTransportation> BillForTransportationList { set; get; }

        public void addTransportationBill()
        {
            AddTransportationBill addDialog = new AddTransportationBill();
            addDialog.ShowDialog();
            if (addDialog.DialogResult==true)
            {
                compShopDataContext.AddToBillForTransportations(addDialog.bill);
                compShopDataContext.SaveChanges();
                BillForTransportationList.Add(addDialog.bill);
            }
        }
    }
}
